package com.jyh.homework.homework4;

public class StudentsTool {
    public void listStudents(Student[] arr) {
        for (Student student : arr) {
            System.out.println("姓名是:"+student.getName()+"年龄是:"+student.getAge()+"成绩是:"+student.getScore());
        }
    }//遍历打印学生信息

    public void getMaxScore(Student[] arr) {
    Integer maxScore=arr[0].getScore();
        for (int i = 0; i < arr.length; i++) {
            if (maxScore<arr[i].getScore()){
                maxScore=arr[i].getScore();
            }
        }
        System.out.println("最高分为:"+maxScore);
    }//获取学生成绩的最高分

    public void getMaxStudent(Student[] arr) {
        Student max=arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (max.getScore()<arr[i].getScore()){
                max=arr[i];
            }
        }
        System.out.println("成绩最高的学员是："+max.getName());
    }//获取成绩最高的学员

    public void getAverageScore(Student[] arr) {
        Integer sum=0;
        Integer count=0;
        for (int i = 0; i < arr.length; i++) {
            sum=sum+arr[i].getScore();
            count++;
        }
        System.out.println(count+"个学生的平均分为："+(sum/count));
    }//获取学生成绩的平均值

    public void getCount(Student[] arr) {
        Integer count=0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].getScore()<60){
                System.out.println("不及格的学员信息：");
                System.out.println("姓名\t年龄\t成绩");
                System.out.println(arr[i].getName()+" "+arr[i].getAge()+"\t"+arr[i].getScore());
                count++;
            }
        }
        System.out.println("不及格的学员数量为："+count+"个");
    }//获取不及格的学员数量
}
